// AWTGridBagLayout.h: interface for the AWTGridBagLayout class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AWTGRIDBAGLAYOUT_H__49185464_418F_11D2_A3F1_006097A44215__INCLUDED_)
#define AFX_AWTGRIDBAGLAYOUT_H__49185464_418F_11D2_A3F1_006097A44215__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "AWTLayout.h"

#define MAXGRIDSIZE           512
#define MINSIZE			          1
#define PREFERREDSIZE	        2

class AWTGridBagLayoutInfo : public AWTObject
{
DECLARE_DYNAMIC(AWTGridBagLayoutInfo)
public:
	AWTGridBagLayoutInfo();
	virtual ~AWTGridBagLayoutInfo();

	int m_width;
	int m_height;
	int m_startx;
	int m_starty;
	int m_minWidth[MAXGRIDSIZE];
	int m_minHeight[MAXGRIDSIZE];
	double m_weightX[MAXGRIDSIZE];
	double m_weightY[MAXGRIDSIZE];
};


class AFX_EXT_CLASS AWTGridBagLayout : public AWTLayout,
                         public AWTLayoutManager
{
DECLARE_DYNAMIC(AWTGridBagLayout)
public:
	AWTGridBagLayout();
	virtual ~AWTGridBagLayout();

	void setConstraints(AWTComponent* comp, AWTGridBagConstraints* constraints) 
	{
		AWTGridBagConstraints* pExistingConstraints = NULL;

		m_comptable.Lookup(comp, (void*&) pExistingConstraints );
		if( pExistingConstraints != NULL)
		{
			delete pExistingConstraints;
			pExistingConstraints = NULL;
		}
		m_comptable.SetAt(comp, new AWTGridBagConstraints(*constraints));
  }

  AWTGridBagConstraints* getConstraints(AWTComponent* comp);
	CPoint getLayoutOrigin();
	void addLayoutComponent(CString* name, AWTComponent* comp){}; 
	void addLayoutComponent(AWTComponent* comp, AWTObject* constraints) 
	{
		setConstraints(comp, (AWTGridBagConstraints*)constraints);
  }
  void removeLayoutComponent(AWTComponent* comp){};
  CSize preferredLayoutSize(AWTContainer* parent) 
	{
    AWTGridBagLayoutInfo* info = GetLayoutInfo(parent, PREFERREDSIZE);
    CSize sz = GetMinSize(parent, info);
		delete info;
		return sz;
  }
  CSize minimumLayoutSize(AWTContainer* parent) 
	{
    AWTGridBagLayoutInfo* info = GetLayoutInfo(parent, MINSIZE);
    CSize sz = GetMinSize(parent, info);
		delete info;
		return sz;
	}
  void layoutContainer(AWTContainer* parent) 
	{
    ArrangeGrid(parent);
  }
	void AdjustForGravity(AWTGridBagConstraints* constraints, CRect* r);
	virtual AWTLayoutManager* getLayoutManager()
		{return static_cast<AWTLayoutManager*>(this);}
	
	int* m_columnWidths;
	int* m_rowHeights;
	int m_columnWidthsLength;
	int m_rowHeightsLength;
	double* m_columnWeights;
	double* m_rowWeights;
	int m_columnWeightsLength;
	int m_rowWeightsLength;

protected:
  AWTGridBagConstraints* lookupConstraints(AWTComponent* comp);
	AWTGridBagLayoutInfo* GetLayoutInfo(AWTContainer* parent, int sizeflag);
	CSize GetMinSize(AWTContainer* parent, AWTGridBagLayoutInfo* info);
	void ArrangeGrid(AWTContainer* parent);

	CMapPtrToPtr m_comptable;
	AWTGridBagConstraints m_defaultConstraints;
	AWTGridBagLayoutInfo* m_layoutInfo;
};

#endif // !defined(AFX_AWTGRIDBAGLAYOUT_H__49185464_418F_11D2_A3F1_006097A44215__INCLUDED_)
